package org.kl.bf.entity.basic;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;
import org.kl.bf.entity.AuditableEntity;
import org.kl.bf.entity.Excel;
import org.kl.bf.utils.BasicConstants;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

//JPA标识
@Entity
@Table(name = "basic_code_values")
public class CodeValues extends AuditableEntity {
	private static final long serialVersionUID = 2459582016646290886L;

	@Excel(exportName = "所属代码表", exportProperty = "tableName")
	private CodeTable codeTable;
	private String codeParentId;
	@Excel(exportName = "代码名称")
	private String codeName;
	@Excel(exportName = "代码值")
	private String codeValue;
	private String iconCls;
	@SuppressWarnings("unused")
	private String pid;
	@Excel(exportName = "父代码名称")
	private String parentCodeName;
	@Excel(exportName = "是否启用", exportConvertSign = 1)
	private Integer enable;

	public CodeValues() {

	}

	public CodeValues(String id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name = "CODE_TABLE_ID")
	public CodeTable getCodeTable() {
		return codeTable;
	}

	public void setCodeTable(CodeTable codeTable) {
		this.codeTable = codeTable;
	}

	public String getCodeParentId() {
		return codeParentId;
	}

	public void setCodeParentId(String codeParentId) {
		if (StringUtils.isBlank(codeParentId)) {
			this.codeParentId = null;
		} else {
			this.codeParentId = codeParentId;
		}
	}

	public String getCodeName() {
		return codeName;
	}

	public void setCodeName(String codeName) {
		this.codeName = codeName;
	}

	public String getCodeValue() {
		return codeValue;
	}

	public void setCodeValue(String codeValue) {
		this.codeValue = codeValue;
	}

	public String getIconCls() {
		return iconCls;
	}

	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}

	@Transient
	@JsonInclude(Include.NON_NULL)
	public String getPid() {
		return getCodeParentId();
	}

	@Transient
	public String getParentCodeName() {
		return parentCodeName;
	}

	public void setParentCodeName(String parentCodeName) {
		this.parentCodeName = parentCodeName;
	}

	public Integer getEnable() {
		return enable;
	}

	public void setEnable(Integer enable) {
		if (enable == null) {
			this.enable = BasicConstants.NO_INT;
		} else {
			this.enable = enable;
		}
	}

	public String enableConvert() {
		return enable == 1 ? "是" : "否";
	}

}
